﻿using System;
using Com.Mathphoenix.MapApps;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace  Com.Mathphoenix.MapApps.NerdDinner.Helpers
{
    public class PhoneValidator
    {
        static IDictionary<string, Regex> countryRegex = new Dictionary<string, Regex>() {
            {"中国",new Regex("^0[1-9]{2,3}-{0,1}\\d{7,8}(-\\d{1,5}$|\\d{0,5}$)")},
            { "USA", new Regex("^[2-9]\\d{2}-\\d{3}-\\d{4}$")},
            { "UK", new Regex("(^1300\\d{6}$)|(^1800|1900|1902\\d{6}$)|(^0[2|3|7|8]{1}[0-9]{8}$)|(^13\\d{4}$)|(^04\\d{2,3}\\d{6}$)")},
            { "Netherlands" , new Regex("(^\\+[0-9]{2}|^\\+[0-9]{2}\\(0\\)|^\\(\\+[0-9]{2}\\)\\(0\\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\\-\\s]{10}$)")}       
        };

        public static bool IsValidNumber(string phoneNumber, string country)
        {
            if (country != null && countryRegex.ContainsKey(country)) return countryRegex[country].IsMatch(phoneNumber);
            else return false;
        }

        public static IEnumerable<string> Countries
        {
            get { return countryRegex.Keys; }
        }
    }
}
